package com.zqj.project.common.exception;

import cn.hutool.core.text.CharSequenceUtil;

import java.io.Serial;

/**
 * @Description: BaseUncheckedException
 * @Author: 22001010704 Zhang Qijian
 * @CreateTime: 2024/6/12 23:41
 * @Version: 1.0
 */
public class BaseUncheckedException extends RuntimeException implements BaseException {

    @Serial
    private static final long serialVersionUID = -778887391066124051L;
    private String message;
    private int code;

    public BaseUncheckedException(Throwable cause) {
        super(cause);
    }

    public BaseUncheckedException(int code, Throwable cause) {
        super(cause);
        this.code = code;
    }

    public BaseUncheckedException(int code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public BaseUncheckedException(int code, String message, Throwable cause) {
        super(cause);
        this.code = code;
        this.message = message;
    }

    public BaseUncheckedException(int code, String format, Object... args) {
        super(CharSequenceUtil.contains(format, "{}") ? CharSequenceUtil.format(format, args) : String.format(format, args));
        this.code = code;
        this.message = CharSequenceUtil.contains(format, "{}") ? CharSequenceUtil.format(format, args) : String.format(format, args);
    }

    @Override
    public String getMessage() {
        return this.message;
    }

    @Override
    public int getCode() {
        return this.code;
    }

}